package com.maikang.exammall.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.maikang.exammall.entity.constant.RepositoryConstant;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Date;

import static com.maikang.exammall.entity.Bill.TABLE_NAME;

@Entity
@Table(name = TABLE_NAME, schema = RepositoryConstant.APP_DB_TABLE_SCHEMA, catalog = RepositoryConstant.APP_DB_TABLE_SCHEMA)
@DynamicUpdate
@DynamicInsert
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true, value = {"hibernateLazyInitializer", "handler"})
@NoArgsConstructor
@AllArgsConstructor
@Data
@EqualsAndHashCode(callSuper=true)
@ToString(callSuper = true)
@SQLDelete(sql = "update " + RepositoryConstant.APP_DB_TABLE_SCHEMA + "." + TABLE_NAME + " set is_deleted = 1 WHERE id = ?")
@Where(clause = " is_deleted = 0")
public class Bill extends AuditEntity<Long> {
    public static final String TABLE_NAME = "mkb_trade_bill";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private Long orderId;
    private String outTradeNo;
    private String transactionId;
    private String prepayId;
    private String nonceStr;
    private String remark;
    private Long totalFee;
    @ApiModelProperty("收支类型 1收入，-1支出")
    private Integer feeType;
    @ApiModelProperty("支付状态 0待处理，-1用户中途取消，1处理中，2交易成功，-2交易失败")
    private Integer status;
    @ApiModelProperty("交易类型, 1-下单收入， -1:退款， -2：企业付款到零钱")
    private Integer transType;


    @ApiModelProperty("向微信发起交易的时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date timeStart;
    @ApiModelProperty("支付过期时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date timeExpire;
    @ApiModelProperty("实际交易时间，微信支付返回的时间，支付完成时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date timeEnd;

    @Override
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    public Long getPrimaryKey() {
        return this.id;
    }

    @Override
    public void setPrimaryKey(Long id) {
        this.id = id;
    }
}
